// 判断两数组是否相同
export function judementSameArr(news: Array<string>, old: Array<string>) {
	let count = 0;
	const leng = old.length;
	for (let i in old) {
		for (let j in news) {
			if (old[i] === news[j]) count++;
		}
	}
	return count === leng ? true : false;
}

//中位数
export function middle(args) {
	// let args=[...arguments]; //收集参数转为数组
	let num = 0;
	args.sort(); //排序
	if (args.length % 2 === 0) { //判断数字个数是奇数还是偶数
		num = ((args[args.length / 2] + args[args.length / 2 - 1]) / 2);//偶数个取中间两个数的平均数
		// return Promise.reject(num);
		return num;
	} else {
		num = args[parseInt(args.length / 2)];//奇数个取最中间那个数
		// return Promise.reject(num);
		return num;
	}
}

//众数
export function majorityElement(nums) {
	let hash = {};
	let majority_element;
	let max_num = 0;
	for (let num of nums) {
		if (hash[num]) {
			hash[num]++;
		} else {
			hash[num] = 1;
		}
		if (hash[num] > max_num) {
			max_num = hash[num];
			majority_element = num;
		}
	}
	if (majority_element == 0) majority_element = 50;
	return Math.abs(majority_element);
}
